home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 26 / AMIGAplus Sonderheft 26 (2000)(Falke)(DE)(Track 1 of 2)[!].iso / Tools / GFX-Viewer / Animviewer / mpegvideo_datatype / classbase.c < prev    next >
C/C++ Source or Header  |  1999-03-29  |  31KB  |  793 lines

  1.  
  2. /*
  3. **
  4. **  $VER: classbase.c 1.11 (7.11.97)
  5. **  mpegvideo.datatype 1.11
  6. **
  7. **  Library routines for a DataTypes class
  8. **
  9. **  Written 1996/1997 by Roland 'Gizzy' Mainz
  10. **  Original example source from David N. Junod
  11. **
  12. */
  13.  
  14.  
  15. /* main includes */
  16. #include "classbase.h"
  17.  
  18. #ifdef __SASC
  19. /* SAS/C compatibly hack. This may be caused by a math library */
  20. __stdargs
  21. void _XCEXIT( long dummy )
  22. {
  23. }
  24. #endif /* __SASC */
  25.  
  26.  
  27. /****** mpegvideo.datatype/--datasheed-- *************************************
  28. *
  29. *   NAME
  30. *       mpegvideo.datatype -- data type for mpeg video streams
  31. *
  32. *   SUPERCLASS
  33. *       animation.datatype
  34. *
  35. *   DESCRIPTION
  36. *       The mpegvideo data type, a sub-class of the animation.datatype, is
  37. *       used to load and play mpeg 1 video streams (Layer I).
  38. *
  39. *   METHODS
  40. *       OM_NEW -- Create a new animation object from a description file. The
  41. *           source may only be a file.
  42. *
  43. *       OM_DISPOSE -- Dispose instance and contents (frames, colormaps etc.),
  44. *           then pass msg to superclass
  45. *
  46. *       OM_UPDATE -- Perform an ICM_CHECKLOOP check, and if succesfull, the
  47. *           method will be executed like OM_SET downstairs.
  48. *
  49. *       OM_SET -- Pass msg to superclass, and if the mpegvideo.datatype
  50. *           instance is the "top instance", call GM_RENDER if retval from
  51. *           superclass was != 0UL.
  52. *
  53. *       ADTM_LOADFRAME -- Fill in struct adtFrame with requested information
  54. *           from internal FrameNode list like bitmap, colormap, samples, etc..
  55. *
  56. *       All other methods are passed unchanged to superclass.
  57. *
  58. *   ATTRIBUTES
  59. *       Following attributes are set by the object and are READ-ONLY for
  60. *       applications:
  61. *       DTA_NominalHoriz        -- same as ADTA_Width
  62. *       DTA_NominalVert         -- same as ADTA_Height
  63. *       DTA_ObjName             -- same as DTA_Name
  64. *       ADTA_Width              -- set by video stream
  65. *       ADTA_Height             -- set by video stream
  66. *       ADTA_Depth              -- set by video stream (or by prefs)
  67. *       ADTA_NumColors          -- set by ADTA_Depth or to the num. of 
  68. *                                  palette entries
  69. *       ADTA_ColorRegisters     -- obj's palette with ADTA_NumColors entries
  70. *       ADTA_CRegs              -- obj's palette with ADTA_NumColors entries
  71. *       ADTA_Frames             -- total number of frames
  72. *       ADTA_FramesPerSecond    -- set by video stream
  73. *       ADTA_ModeID             -- calculated internally or set by prefs
  74. *       ADTA_KeyFrame           -- key frame
  75. *       ADTA_Sample             -- sample (optional, if a sample is attached)
  76. *       ADTA_SampleLength       -- sample length (optional, see ADTA_Sample)
  77. *       ADTA_Period             -- sample period (optional, see ADTA_Sample)
  78. *       ADTA_Volume             -- sample volume (optional, see ADTA_Sample)
  79. *       ADTA_Cycles             -- sample cycle  (optional, see ADTA_Sample)
  80. *
  81. *   BUGS
  82. *       - If the mpeg video stream is not 100% standart conform,
  83. *         the decoder part of this datatype will CRASH your machine.
  84. *         Innocent memory will be overwritten !!
  85. *
  86. *       - If you don't have my "paranimdtcpatch" patch running,
  87. *         animation.datatype (animation.datatype 40.7 (28.09.93)) subclasses
  88. *         will suffer under timing problems when two or more
  89. *         animation.datatype objetcs are playing. I've released a matching
  90. *         patch, DON'T blame me for this bug. Any comments for this problem
  91. *         should be related  to the "paranimdtcpatch" project.
  92. *         "paranimdtcpatch" is available in the aminet
  93. *         ("util/dtype/panimdtcptch012.LhA").
  94. *         NOTE that animation.datatype V41 does NOT require the patch
  95. *         anymore.
  96. *
  97. *       - In large videos, the frames at the end will be played slower than
  98. *         those at the beginning of the file. This is the result of the
  99. *         sequential search internally used (only serious with more than 25000
  100. *         frames (mc68030/50mhz)).
  101. *         Will be fixed.
  102. *
  103. *       - The LOADALL mode does not work perfectly. It sometimes "forgets" to
  104. *         fill some frames during loading.
  105. *
  106. *       - The time code in the NOLODALL mode is slightly wrong (I assume up
  107. *         to +/- 6 frames).
  108. *
  109. *       - The NOPFRAMES and NOBFRAMES options are incompatible with the
  110. *         NOLOADALL mode.
  111. *
  112. *       - CyberGFX 24 bit output mode uses 32 bit ARGB bitmaps, but the A
  113. *         (alpha) byte is not set to 0xFF (visible), instead it is set to 0.
  114. *         The same for 15 bit output mode, where the MSB is a alpha mask bit.
  115. *
  116. *   TODO
  117. *       - better error handling (and error messages)
  118. *
  119. *       - code cleanup
  120. *
  121. *       - bug fixing
  122. *
  123. *       - Writing an amigaguide document
  124. *
  125. *       - EHB
  126. *
  127. *   HISTORY
  128. *       V1.1
  129. *         First (official) public release.
  130. *
  131. *       V1.2
  132. *         Major code cleanup. I decided to rebuild the whole project from
  133. *         scratch instead of releasing my internal V1.8. The reason is that
  134. *         many things coded in it wasn't done with the required care. Now
  135. *         I try to fix this.
  136. *
  137. *         - Sorry, but in the V1.1 release, I've forgotten the COPYRIGHT
  138. *           notice. Because I don't have the original ones (my code was a
  139. *           mergin of mpeg_play 1.X, 2.0, I've taken them from the
  140. *           mpeg_play 2.0 distribution).
  141. *
  142. *         - Implemented the NOPFRAMES and NOBFRAMES switch (for those people
  143. *           who like it).
  144. *
  145. *         - The loader now returns usefull return codes instead of failing
  146. *           silently.
  147. *
  148. *         - Decrased the default depth from 7 to 5 planes. This is a more
  149. *           reliable default value for grayscale mpeg videos (screen or
  150. *           window).
  151. *
  152. *         - Implemented "DICECOLOR" and "ORDERED" dithering.
  153. *           The options COLORERROR and DICESKIP are for fine-tuning
  154. *           speed <--> color output.
  155. *
  156. *         - Introduced MAXFRAME (maximum number of frame to load) and
  157. *           SKIPFRAMES to allow loading of large videos.
  158. *
  159. *         - MODEID option added (for those which don't like the default
  160. *           settings).
  161. *
  162. *         - The datatypes descriptor file was WRONG. Now it should be correct.
  163. *           If not, send me a mail (and if possible, the sample file which
  164. *           won't work (packed with LhA for compression and CHECKSUMMING).
  165. *           (Later versions of the descriptor should use additional code
  166. *           to check the data).
  167. *
  168. *       V1.3
  169. *         - COLOR output implemented.
  170. *
  171. *         - DICECOLOR: Found a bug (?? very strange one ??) in my code which
  172. *           avoids the usage of a frame palette. DICECOLOR was intended
  173. *           to produce high-quality per frame color remapping instead using
  174. *           a global anim palette. Broken (e.g. working, but after a frame is
  175. *           finished, the color table isn't cleared for now...).
  176. *
  177. *         - I found out that the most time is consumed by the WritePixelArray
  178. *           and copy functions. Later versions should contain a custom
  179. *           WritePixelArray replacement which should be able to write directly
  180. *           into FAST-RAM instead of writing into CHIP-RAM and them do a copy
  181. *           into FAST-RAM. This would save __MUCH__ time.
  182. *
  183. *         - Silly mistake: A
  184. *           SetIoErr( 0L ); len = FRead( ..., requested ); sequence returns
  185. *           under various fs IoErr() == (-1L) or something else. The loader
  186. *           then aborts with this error code. (The code worked with RAM: disk,
  187. *           my VideoCD-fs ("white book" mode)) and AMICDROM, but wasn't tested
  188. *           with FFS or something else).
  189. *           The code now uses Read instead of FRead, checks for
  190. *           (len != requested), and only if TRUE IoErr() will be checked for
  191. *           any error.
  192. *
  193. *         - Introduced BUFFER preferences option.
  194. *
  195. *         - A CTRL-D signal send to the loading process now stops the load.
  196. *           This feature was implemented in V1.2, but I forgot to write it
  197. *           down here.
  198. *
  199. *         - The autodoc now has a TOC (table of contents).
  200. *
  201. *         - Support for Martin Apel's VMM (Virtual Memory Manager).
  202. *           (USEVMM switch in prefs file). The bitmaps can now be in virtual
  203. *           memory (the colormaps are traditional allocated by GetColorMap
  204. *           and cannot be in virtual memory (not yet nor in the future !)).
  205. *           The mpegvideo.datatype uses the vmm.library, this allows
  206. *           virtual memory usage even if the vmm.prefs disables virtual memory
  207. *           for all other tasks.
  208. *           NOTE: VMM is Shareware !!
  209. *
  210. *       V1.4
  211. *         - vmm.library is now opened on demand (e.g. the USEVMM switch was
  212. *           set in the prefs file) inside the OM_NEW method.
  213. *           This fixes two problems:
  214. *           First: vmm.library was opened even it wasn't used.
  215. *           Second: OpenLibrary( "vmm.library", ... ) inside the LibInit
  216. *           function caused various problems.
  217. *           vmm.library will be closed by LibExpuge function.
  218. *
  219. *         - Removed serial verbose output. Now, if the VERBOSE switch was set
  220. *           in the prefs file, all verbose output will be printed to
  221. *           "CON://///auto/wait/close/inactive".
  222. *
  223. *         - Set the SC NOOPTIMIZERPEEPHOLE switch for mc68060 support:
  224. *           phase5 said that SAS/C 6.56 has a small bug in the peephole
  225. *           optimizer which may cause trouble with mc68060. The peephole
  226. *           optimizer will be turned on again if I know more details (and
  227. *           a workaround).
  228. *
  229. *         - The product of LUM_RANGE * CR_RANGE * CB_RANGE was limited to
  230. *           a maximum of 512.  LUM_RANGE, CR_RANGE, CB_RANGE can now have
  231. *           any positive value up to 255. A value of 0 is treated as 1,
  232. *           fixing the problem of a possible division by zero.
  233. *
  234. *         - Found a bug in COLOR dithering, which causes quality loss and
  235. *           color disorientation. Fixing this bug will take MUCH time.
  236. *           Not fixed yet.
  237. *
  238. *         - To match the "DataTypes proposal", changes have been made:
  239. *           1. The location of the prefs file is now ENV:Classes/DataTypes/
  240. *              mpegvideo.prefs instead of ENV:DataTypes/mpegvideo.prefs
  241. *           2. Subclasses of mpegvideo.datatype are not supported. Any
  242. *              attempt to create a subclass object of mpegvideo.datatype
  243. *              will be rejected by mpegvideo.datatype.
  244. *
  245. *         - Partial code cleanup. I've implemented partial support for
  246. *           output depths up to 16 bits. Currently, I'm limited to a maximum
  247. *           depth of 8 bitplanes (e.g. 256 colors) for two reasons:
  248. *           First, the system WritePixelArray8 function handles only byte
  249. *           width pen indexes, second, animation.datatype handles only a
  250. *           bitmaps up to 8 planes. Future releases of animation.datatype may
  251. *           handle deeper bitplanes. (Custom players like my DBufDTAnim which
  252. *           are using their own display code are able to display deeper
  253. *           bitmaps yet.)
  254. *
  255. *         - Found out a little problem: When using VMM (swap file) with
  256. *           Enforcer, enforcer hits may block your system (occured on a
  257. *           A2000 Apollo 2030 mc68030 board).
  258. *           Who knows an answer for this problem ?
  259. *
  260. *       V1.5
  261. *         Minor changes to support special compiled versions for 68020+,
  262. *         fpu etc.
  263. *
  264. *         - Implemented the IGNOREERRORS switch, which attempts to ignore any
  265. *           error during loading.
  266. *
  267. *         - Removed some dead code.
  268. *
  269. *       V1.6
  270. *         The datatypes supports now scaling and sound. Sound was implemented
  271. *         for two reasons:
  272. *         1. For those streams which are distributed with a matching sound
  273. *            file.
  274. *         2. I'm reworking mpegsystem.datatype (which can play system streams,
  275. *            e.g. video with interleaved audio). The goal is to implement
  276. *            mpegsystem.datatype as a subclass of mpegvideo.datatype. The
  277. *            audio stream will be parsed using mpegaudio.datatype.
  278. *         Note that mpegvideo.datatype is still a GID_ANIMATION type datatype.
  279. *         The GID_#? idetifiers belongs to the source data, not the
  280. *         modifications done by a datatype code (a mpeg 1 video stream does
  281. *         not contain any audio information, the sound is attached later).
  282. *
  283. *         - Implemented the WIDTH and HEIGHT options in the prefs file to
  284. *           support scaling.
  285. *
  286. *         - Implemented SAMPLE and VOLUME options to support sound.
  287. *
  288. *         - Now uses BestModeID for selecting the screen mode of the
  289. *           animation. The MODEID preference option overides this.
  290. *           The old behavior was to set the ADTA_ModeID attribute only if the
  291. *           MODEID prefs option was set, otherwise the default from
  292. *           animation.datatype was taken (which was everytimes 0).
  293. *
  294. *         - Fixed the FPS preference option. If it was set, the value was got
  295. *           from the depth option instead using the given value.
  296. *
  297. *         - Implemented a processing gauge as requested by Allan Odgaard
  298. *           (Duff@DK-Online.DK) and many other people. The matching
  299. *           NOPROGRESSGAUGE switch disables it. If the input filehandle is a
  300. *           pipe, the gauge may not work properly.
  301. *
  302. *         - Implemented a lowermem limit (MINTOTALMEM option) for those
  303. *           people who wants to see at least the beginning of a big anim
  304. *           (idea by Allan Odgaard (Duff@DK-Online.DK)).
  305. *
  306. *         - Implemented multi-line preferences, supports comments and
  307. *           per-project settings (MATCHPROJECT option). The old preference
  308. *           files/vars are compatible.
  309. *
  310. *         - The stack size for the OM_NEW method is now checked. If the
  311. *           required size (curretly 12kb) isn't available, a requester will
  312. *           notify the user and the method returns an error.
  313. *
  314. *       V1.7
  315. *         - Recompiled with SAS/C 6.57. Switched the peephole optimizer on
  316. *           (see V1.4 bugs).
  317. *
  318. *         - Rewrote the DICECOLOR dithering/remapping code. The DICECOLOR
  319. *           color mode now creates a colormap per frame (animation.datatype
  320. *           40.7 does not support these colormap changes per frame (it's
  321. *           output looks like a color trash). Custom animation players which
  322. *           uses animation.datatype subclasses for loading (like my
  323. *           DBufDTAnim) don't have this problem. animation.datatype V41 will
  324. *           support these colormaps-per-frame.
  325. *
  326. *           I changed the algorithm from a single-pass into a multi-pass
  327. *           operation, which allows the code to run on other output modes
  328. *           like ORDERED or FS (Floyd-Steinberg). A side-effect of this
  329. *           change is that options like COLORERROR and DICESKIP are selected
  330. *           automatically, which is more user-friendly.
  331. *
  332. *           If you want to get the old DICECOLOR output, use
  333. *           DITHER=COLOR PALETTEPERFRAME options.
  334. *
  335. *         - The mpegvideo.datatype uses 24 bit-colors internally and
  336. *           writes 32 bits per (r,b,g) gun. Now the high order bits of each
  337. *           color gun are replicated through the whole INT32.
  338. *
  339. *         - Fixed a bug in the SAMPLE option, which caused possible crashes.
  340. *
  341. *         - Fixed a bug in LibExpunge (didn't check lib_OpenCnt), which is
  342. *           also present in all my other external BOOSI classes (and
  343. *           datatypes).
  344. *           Thanks to Guenter Niki (gniki@informatik.uni-rostok.de) for
  345. *           reporting this bug.
  346. *
  347. *         - Implemented the mpeg saving code (mpeg encoder). Currently,
  348. *           only mpeg-1 streams are written out.
  349. *           (Will be enabled in the public versions ONLY upon request;
  350. *           code is currently under construction).
  351. *
  352. *         - Increased the stack requirements from 12kb up to 16kb, mainly
  353. *           to allow more recursive operations.
  354. *
  355. *         - Implemented random access to frames (e.g you need not to load
  356. *           the whole animation, decoding is done on the fly).
  357. *           (Will be enabled in the public versions ONLY upon request;
  358. *           code is currently under construction,
  359. *           the matching LOADALL switch it set everytimes).
  360. *
  361. *       V1.8
  362. *         - Added partial support for mpeg-2 (MPEG-2 does NOT work yet !),
  363. *           both encoder+decoder.
  364. *
  365. *         - Added my own WritePixelArray8 replacement, which operates
  366. *           directly on the fast-mem bitmaps. This saves some internal
  367. *           copies, chipmem buffer for WPA8 etc.
  368. *
  369. *         - Added my own scaling routine, replacing
  370. *           graphics.library/BitMapScale (which needs chipmem as temp.
  371. *           buffer).
  372. *           Does not work properly yet.
  373. *
  374. *         - Fixed the gauge, which didn't work correctly with large streams
  375. *           (>= 8MB).
  376. *           Fixed.
  377. *
  378. *         - The gauge ha now a text info, which shows the remaining time
  379. *           to decode.
  380. *
  381. *         - Added experimental stack swapping code. The "Need more stack"-
  382. *           requester has been removed for this reason.
  383. *
  384. *           This also fixes a possible deadlock of "input.device" because
  385. *           the GM_LAYOUT method was running with low stack.
  386. *           Fixed.
  387. *
  388. *         - Color table setup now retries color table build with an increased
  389. *           COLORERROR if table (set by LUM_RANGE * CR_RANGE * CB_RANGE) does
  390. *           not fit. This allows any #?_RANGE value.
  391. *
  392. *         - Fixed different problems within color setup. Now this should
  393. *           work with a higher quality, and a little bit faster.
  394. *
  395. *         - Fixed the descriptor, which din't match all mpeg video streams.
  396. *           Fixed.
  397. *
  398. *         - DTM_WRITE should return ERROR_NOT_IMPLEMENTED if DTWM_RAW mode is
  399. *           requested (becuase the encoder has been disabled, e.g. commented
  400. *           out). Now this is correctly done.
  401. *           Fixed.
  402. *
  403. *         - The mc68060-Version now checks for the AFF_68060 (1L<<7) execbase
  404. *           flag instead using the AFF_68040.
  405. *           Fixed.
  406. *
  407. *         - Added QUALITY prefs option and matching float-dct code.
  408. *
  409. *       V1.9
  410. *         - Recompiled with SAS/C 6.58. Should fix some mc68060 related
  411. *           problems.
  412. *
  413. *         - Minor and major housekeeping changes.
  414. *
  415. *         - Added HAM code and HAM dither option as requested by many people.
  416. *           Thanks to Olaf Barthel for his fast HAM conversion code.
  417. *
  418. *         - DTA_ObjName is now set (and equals to DTA_Name).
  419. *
  420. *         - GM_LAYOUT/DTM_PROCLAYOUT code has been removed because
  421. *           animation.datatype class does the same.
  422. *
  423. *         - Removed NOREMAP switch (and matching DTM_FRAMEBOX code) because
  424. *           this was an ugly hack. After all, it seems that MuliView 
  425. *           sets ADTA_Remap to FALSE on it's custom screens, and that
  426. *           using ADTA_Remap == FALSE on a screen which does not have the
  427. *           matching size may cause trouble.
  428. *
  429. *         - ADTA_NumColors is now set to the number of used colors instead
  430. *           of 1UL << anim_depth. This saves some pens when allocating
  431. *           shared pens on shared screens.
  432. *           When palette-per-frames are used, the number of colors equals to
  433. *           1UL << anim_depth again.
  434. *
  435. *         - Moved scaling code before dithering code. It now scales the lum,
  436. *           cr, cb data, which is more usefull when doing ordered or HAM
  437. *           dithering.
  438. *
  439. *         - VMM support seems to be safe...
  440. *
  441. *         - Changed the whole prefs-system. Now the defaults options are more
  442. *           usefull and are adapted correctly to some settings.
  443. *
  444. *         - DITHER option now defaults to HAM, for those people who don't
  445. *           like to edit the prefs-file.
  446. *
  447. *         - Added NOPALETTEPERFRAME/S, PFRAMES/S, BFRAMES/S, NOLOADALL/S,
  448. *           PROGRESSGAUGE/S, NOQUALITY/S switches to support multi-line
  449. *           prefs-files which uses the MATCHPROJECT feature.
  450. *
  451. *         - Internal timing now uses animation.datatype V41
  452. *           ADTA_TicksPerFrame instead of ADTA_FramesPerSecond. This
  453. *           makes timing more precise.
  454. *           (ADTA_TicksPerFrame means 1200 / fps, based on realtime.library's
  455. *           timing model).
  456. *
  457. *         - Increased the decoding the speed a little bit. But this may affect
  458. *           stability if someone feeds a corrupt mpeg file in the datatype.
  459. *           I try to fix the problem...
  460. *
  461. *         - Now uses Peter McGavin's (p.mcgavin@irl.cri.nz) WritePixelArray8
  462. *           code (the C version).
  463. *
  464. *         - Fixed the encoder stack problem.
  465. *
  466. *         - The encoder now has no problems with dynamic frame delays (e.g.
  467. *           alf_Duration field in adtFrame).
  468. *
  469. *         - The SKIP option now uses struct adtFrame -> alf_Duration instead
  470. *           of creating empty frames. This causes that the SKIPFRAMES option
  471. *           works only with animation.datatype V41.
  472. *
  473. *         - Fixed the bug that the last sample might be too long, which
  474. *           caused unallocated memory reads (but only a few bytes) and small
  475. *           clicks at the end of the animation.
  476. *
  477. *         - The startup-code has been rewritten, the code now gurantees that
  478. *           the order of OpenLibrary and CloseLibrary are correct and in a
  479. *           more usefull order.
  480. *
  481. *         - Updated the autodoc a little bit.
  482. *
  483. *       V1.10
  484. *         INTERNAL RELEASE
  485. *
  486. *         - Large code cleanup.
  487. *
  488. *         - If we reach the file end, we now add a end of sequence code
  489. *           manually to avoid any problems if we does not see the end code
  490. *           (this occurs in the NOLOADALL mode in the past...).
  491. *
  492. *         - Removed all remaining parts of "recmpeg". Now I'm allowed to
  493. *           release the source :-)
  494. *
  495. *         - Moved the encoder to the mpegvideo.datatype V2.
  496. *
  497. *         - Moved the YUV -> 24-bit interleaved-planar to
  498. *           mpegvideo.datatype V2.
  499. *
  500. *         - Removed the whole MPEG-2 support. mpegvideo.datatype V2 does this
  501. *           better.
  502. *
  503. *         - Wrote a replacement for the 24 bit planar code (currently
  504. *           non-interleaved).
  505. *
  506. *         - Rewrote the 24/15/16 bit dither code.
  507. *           Should fix some visual problems.
  508. *
  509. *         - Fixed the bug that animation.datatype V41 wasn't detected
  510. *           correctly (the version check didn't match, therefore
  511. *           any V41 related features were not used).
  512. *           Fixed.
  513. *
  514. *         - Added GAMMACORRECT and CHROMACORRECT options.
  515. *
  516. *         - Removed BestModeIDA code because animation.datatype does the
  517. *           same job (better).
  518. *
  519. *         - Fixed the bug that MODEID=0 turns the internal mode selection
  520. *           on instead of using LORES.
  521. *           This also requires a change in the prefs behaviour, the
  522. *           default value for the MODEID option is now "-1".
  523. *           Fixed.
  524. *
  525. *         - Removed all internal accesses to ADTA_BitMapHeader because they
  526. *           are unneccesary (dead code).
  527. *
  528. *         - The VERBOSE output is now turned on if a serious error occurs.
  529. *
  530. *         - If frames are skipped (using the NOPFRAMES or NOBFRAMES option)
  531. *           now the duration of the last frame is increased to get sync
  532. *           with the stream time.
  533. *
  534. *         - Fixed the bug that the total number of frames might be incorrect
  535. *           in rare cases.
  536. *           Fixed.
  537. *
  538. *         - Fixed a bug in the color setup of ORDERED dithering which
  539. *           caused that the values runned from 0 upto 256 (256 == 0 in an
  540. *           UBYTE). Now the color values are correctly running from 0-255.
  541. *           Fixed.
  542. *
  543. *           Fixed the same bug in GRAY dither setup.
  544. *           Fixed.
  545. *
  546. *       V1.11
  547. *         - Enabled the NOLOADALL mode for the public.
  548. *
  549. *         - Small code cleanup to remove some unneccesary parts of code
  550. *           (mainly the obsolete encoder support).
  551. *
  552. *         - Fixed the bug that the depth of a CyberGFX ARGB bitmap must be 32
  553. *           instead of 24.
  554. *           Fixed.
  555. *
  556. *         - Added some safety in CyerGFX LockBitMap handling (which has a bug
  557. *           in tag parsing).
  558. *
  559. *         - Added workaround for NOLOADALL mode that ADTM_LOADFRAME returns
  560. *           1UL instead of NULL if it forgets a frame (to avoid that the
  561. *           playback stops...).
  562. *           Not nice...
  563. *
  564. *         - Fixed a bug in 24bit -> HAM dithering introduced in V1.10.
  565. *           Fixed.
  566. *
  567. *         - Replaced stack swapping code by a "standard module".
  568. *
  569. *         - Increased the "default" buffer size from 4096 up to 16384.
  570. *           This makes the gauge less accurate for small streams, but
  571. *           gives a small speedup when parsing large streams.
  572. *
  573. *   SEE ALSO
  574. *       animation.datatype,
  575. *       mpegsystem.datatype, mpegvideo.datatype
  576. *       picmovie.datatype,
  577. *       paranimdtcpatch
  578. *
  579. *******************************************************************************
  580. *
  581. */
  582.  
  583.  
  584.  
  585. /*****************************************************************************/
  586.  
  587. DISPATCHERFLAGS
  588. struct IClass *ObtainMPEGVideoEngine( REGA6 struct ClassBase *classbase )
  589. {
  590.     return( (classbase -> cb_Lib . cl_Class) );
  591. }
  592.  
  593. /*****************************************************************************/
  594.  
  595. DISPATCHERFLAGS
  596. struct Library *LibInit( REGD0 struct ClassBase *classbase, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
  597. {
  598. #ifdef USEIEEELIB
  599.     extern struct Library *MathIeeeDoubBasBase;
  600. #endif /* USEIEEELIB */
  601.  
  602.     classbase -> cb_SegList = seglist;
  603.     classbase -> cb_SysBase = sysbase;
  604.  
  605.     InitSemaphore( (&(classbase -> cb_Lock)) );
  606.  
  607. #ifdef REQUIREDAFF
  608.     /* Check if the requested cpu/fpu is available*/
  609.     if( ((classbase -> cb_SysBase -> AttnFlags) | REQUIREDAFF) != (classbase -> cb_SysBase -> AttnFlags) )
  610.     {
  611.       return( NULL );
  612.     }
  613. #endif /* REQUIREDAFF */
  614.  
  615.     /* Requires at least Kick 3.0 */
  616.     if( (classbase -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
  617.     {
  618.       /* Obtain ROM libs */
  619.       if( classbase -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
  620.       {
  621. #undef GfxBase
  622.         if( classbase -> cb_GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 39UL ) )
  623.         {
  624.           classbase -> cb_CyberGfxBase = OpenLibrary( CYBERGFXNAME, CYBERGFXVERSION );
  625.  
  626.           if( classbase -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
  627.           {
  628.             if( classbase -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
  629.             {
  630. #ifdef USEIEEELIB
  631.               if( MathIeeeDoubBasBase = OpenLibrary( "mathieeedoubbas.library", 38UL ) )
  632.               {
  633. #endif /* USEIEEELIB */
  634.                 /* vmm.library will be opened on demand (see dispatch.c) */
  635.                 classbase -> cb_VMMBase = NULL;
  636.  
  637.                 return( (&(classbase -> cb_Lib . cl_Lib)) );
  638.  
  639. #ifdef COMMENTED_OUT
  640.                 CloseLibrary( MathIeeeDoubBasBase );
  641. #endif /* COMMENTED_OUT */
  642.  
  643. #ifdef USEIEEELIB
  644.               }
  645.  
  646.               CloseLibrary( (classbase -> cb_DOSBase) );
  647. #endif /* USEIEEELIB */
  648.             }
  649.  
  650.             CloseLibrary( (classbase -> cb_IntuitionBase) );
  651.           }
  652.  
  653.           CloseLibrary( (classbase -> cb_CyberGfxBase) );
  654.           CloseLibrary( (&(classbase -> cb_GfxBase -> LibNode)) );
  655.         }
  656.  
  657.         CloseLibrary( (classbase -> cb_UtilityBase) );
  658.       }
  659.     }
  660.  
  661.     return( NULL );
  662. }
  663.  
  664. /*****************************************************************************/
  665.  
  666. DISPATCHERFLAGS
  667. LONG LibOpen( REGA6 struct ClassBase *classbase )
  668. {
  669.     LONG retval = (LONG)classbase;
  670.     BOOL success = TRUE;
  671.  
  672.     ObtainSemaphore( (&(classbase -> cb_Lock)) );
  673.  
  674.     /* Use an internal use counter */
  675.     classbase -> cb_Lib . cl_Lib . lib_OpenCnt++;
  676.     classbase -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
  677.  
  678.     if( (classbase -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
  679.     {
  680.       if( (classbase -> cb_Lib . cl_Class) == NULL )
  681.       {
  682.         success = FALSE;
  683.  
  684.         if( classbase -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
  685.         {
  686.           if( classbase -> cb_SuperClassBase = OpenLibrary( "datatypes/animation.datatype", 39UL ) )
  687.           {
  688.             if( classbase -> cb_Lib . cl_Class = initClass( classbase ) )
  689.             {
  690.               success = TRUE;
  691.             }
  692.           }
  693.         }
  694.       }
  695.     }
  696.  
  697.     if( !success )
  698.     {
  699.       CloseLibrary( (classbase -> cb_SuperClassBase) );
  700.       CloseLibrary( (classbase -> cb_DataTypesBase) );
  701.  
  702.       classbase -> cb_DataTypesBase = classbase -> cb_SuperClassBase = NULL;
  703.  
  704.       (classbase -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  705.  
  706.       retval = 0L;
  707.     }
  708.  
  709.     ReleaseSemaphore( (&(classbase -> cb_Lock)) );
  710.  
  711.     return( retval );
  712. }
  713.  
  714. /*****************************************************************************/
  715.  
  716. DISPATCHERFLAGS
  717. LONG LibClose( REGA6 struct ClassBase *classbase )
  718. {
  719.     LONG retval = 0L;
  720.  
  721.     ObtainSemaphore( (&(classbase -> cb_Lock)) );
  722.  
  723.     if( classbase -> cb_Lib . cl_Lib . lib_OpenCnt )
  724.     {
  725.       (classbase -> cb_Lib . cl_Lib . lib_OpenCnt)--;
  726.     }
  727.  
  728.     if( ((classbase -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (classbase -> cb_Lib . cl_Class) )
  729.     {
  730.       if( FreeClass( (classbase -> cb_Lib . cl_Class) ) )
  731.       {
  732.         classbase -> cb_Lib . cl_Class = NULL;
  733.  
  734.         CloseLibrary( (classbase -> cb_SuperClassBase) );
  735.         CloseLibrary( (classbase -> cb_DataTypesBase) );
  736.       }
  737.       else
  738.       {
  739.         classbase -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  740.       }
  741.     }
  742.  
  743.     ReleaseSemaphore( (&(classbase -> cb_Lock)) );
  744.  
  745.     if( (classbase -> cb_Lib . cl_Lib . lib_Flags) & LIBF_DELEXP )
  746.     {
  747.       retval = LibExpunge( classbase );
  748.     }
  749.  
  750.     return( retval );
  751. }
  752.  
  753. /*****************************************************************************/
  754.  
  755. DISPATCHERFLAGS
  756. LONG LibExpunge( REGA6 struct ClassBase *classbase )
  757. {
  758.     BPTR                   seg;
  759. #ifdef USEIEEELIB
  760.     extern struct Library *MathIeeeDoubBasBase;
  761. #endif /* USEIEEELIB */
  762.  
  763.     if( classbase -> cb_Lib . cl_Lib . lib_OpenCnt )
  764.     {
  765.       classbase -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
  766.  
  767.       seg = NULL;
  768.     }
  769.     else
  770.     {
  771.       Remove( (&(classbase -> cb_Lib . cl_Lib . lib_Node)) );
  772.  
  773.       seg = classbase -> cb_SegList;
  774.  
  775.       CloseLibrary( (classbase -> cb_VMMBase) );
  776. #ifdef USEIEEELIB
  777.       CloseLibrary( MathIeeeDoubBasBase );
  778. #endif /* USEIEEELIB */
  779.       CloseLibrary( (classbase -> cb_DOSBase) );
  780.       CloseLibrary( (classbase -> cb_IntuitionBase) );
  781.       CloseLibrary( (classbase -> cb_CyberGfxBase) );
  782.       CloseLibrary( (&(classbase -> cb_GfxBase -> LibNode)) );
  783.       CloseLibrary( (classbase -> cb_UtilityBase) );
  784.  
  785.       FreeMem( (APTR)((ULONG)(classbase) - (ULONG)(classbase -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((classbase -> cb_Lib . cl_Lib . lib_NegSize) + (classbase -> cb_Lib . cl_Lib . lib_PosSize)) );
  786.     }
  787.  
  788.     return( (LONG)seg );
  789. }
  790.  
  791.  
  792.  
  793.